package com.tanhua.server.controller;

import com.tanhua.model.db.Answer;
import com.tanhua.model.vo.QuestionnaireVo;
import com.tanhua.model.vo.ReportVo;
import com.tanhua.server.service.QuestionnaireService;
import com.tanhua.server.service.TestSoulService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @Version 1.0
 * @Author aao
 * @Date 2022/2/21 15:12
 * @Description 测灵魂控制层
 */
@RestController
@RequestMapping("/testSoul")
public class TestSoulController {

    //问卷服务
    @Autowired
    private QuestionnaireService questionnaireService;

    @Autowired
    private TestSoulService testSoulService;

    /**
     * 测灵魂-查看结果
     *
     * @param reportId
     * @return
     */
    @GetMapping("/report/{reportId}")
    public ResponseEntity findReport(@PathVariable Long reportId) {
        ReportVo reportVo = testSoulService.findReport(reportId);
        return ResponseEntity.ok(reportVo);
    }

    /**
     * 测灵魂-问卷列表
     *
     * @return
     */
    @GetMapping
    public ResponseEntity findQuestionnaireList() {
        List<QuestionnaireVo> questionnaireVoList = testSoulService.findQuestionnaireList();
        return ResponseEntity.ok(questionnaireVoList);
    }

    /**
     * 提交问卷
     *
     * @param
     * @return
     */
    @PostMapping
    public ResponseEntity submit(@RequestBody Map<String, List<Answer>> Answer) {
        Long reportId = questionnaireService.submit(Answer);
        return ResponseEntity.ok(reportId.toString());
    }
}
